#ifndef __SPI_FLASH_H__
#define __SPI_FLASH_H__
#include "spi_api.h"

//
// Platform Nor Flash Functions
//
#define SIZE_4KB        0x00001000
#define SIZE_32KB       0x00008000
#define SIZE_64KB       0x00010000
#define SIZE_1MB        0x00100000

#define SPI_FLASH_BASE 0x0
#define SPI_FLASH_SIZE 0x1000000 //16MB

#if 1 /*gd32q64*/
//Command
#define W25X_WRITE_ENABLE           0x06
#define W25X_WRITE_DISABLE          0x04
#define W25X_READ_STATUSREG         0x05
#define W25X_WRITE_STATUSREG        0x01
#define W25X_READ_DATA              0x03
#define W25X_FASTREAD_DATA          0x0B
#define W25X_WRITE_PAGE             0x02
#define W25X_SEC_ERASE              0x20
#define W25X_32K_ERASE              0x52
#define W25X_64K_ERASE              0xD8
#define W25X_CHIP_ERASE             0xC7
#define W25X_POWERDOWN              0xB9
#define W25X_RELEASE_POWERDOWN      0xAB
#define W25X_DEVICEID               0x90
#define W25X_MANUFACTDEVICEID       0x90
#define W25X_JEDECDEVICEID          0x9F
#endif

//int flash_reset(int *spi_fd);
int flash_readID(int *spi_fd);
int flash_write_enable(int *spi_fd);
int flash_write_disable(int *spi_fd);
int spi_flash_read(int *spi_fd, uint32_t address, uint8_t *buffer, size_t lens);
int spi_flash_write(int *spi_fd, uint32_t address, const uint8_t *data, size_t len);
int spi_flash_erase_chip(int *spi_fd);
int spi_flash_erase_sec(int *spi_fd, uint32_t address, uint32_t address_end);

#endif /*__SPI_FLASH_H__*/